<template>
  <div>
     <!--面包屑导航区-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getOrderList()">
            <el-button slot="append" icon="el-icon-search" @click="getOrderList()"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList" border>
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price" width="100"></el-table-column>
        <el-table-column label="是否付款" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status === '0' " type="warning">未付款</el-tag>
            <el-tag v-else type="success">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send" width="100"></el-table-column>
        <el-table-column label="下单时间" prop="create_time" width="180">
          <template slot-scope="scope">{{scope.row.create_time | dateformat}}</template>
        </el-table-column>
        <el-table-column label="操作" width="150">
          <el-button type="primary" size="mini" @click="showEditDialog()">编辑</el-button>
          <el-button type="info" size="mini" @click="getOrderInfoprogress()">详细</el-button>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </el-card>
  <!-- 修改地址对话框 -->
  <el-dialog title="修改地址" :visible.sync="editDialogVisible" width="30%">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="省市区/县">
        <el-cascader v-model="citySelectkeys" :options="cityData" :props="cityProp"></el-cascader>
      </el-form-item>
      <el-form-item label="详细地址">
        <el-input></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="editDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
    </span>
  </el-dialog>
  <!-- 物流信息对话框 -->
  <el-dialog title="物流信息" :visible.sync="showDialogVisible" width="50%">
    <el-timeline>
    <el-timeline-item v-for="(item, index) in orderInfoList" :key="index"
    :timestamp="item.time" :color="'green'">{{item.context}}</el-timeline-item>
  </el-timeline>
  </el-dialog>

  </div>
</template>

<script>
// 导入省市区数据
import cityData from './city_data.js'
export default {
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      orderList: [],
      total: 0,
      // 编辑框显示与否
      editDialogVisible: false,
      // 省市区数据
      cityData: cityData,
      citySelectkeys: [],
      cityProp: {
        label: 'label',
        value: 'value',
        children: 'children'
      },
      form: {},
      // 物流信息查看对话框
      showDialogVisible: false,
      // 记录物流信息数据
      orderInfoList: []
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    // 获取订单列表数据
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      if (res.meta.status !== 200) return this.$message.error('获取订单列表失败')
      this.$message.success('获取订单列表成功')
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 点击页数的事件
    handleCurrentChange (newCurrent) {
      this.queryInfo.pagenum = newCurrent
      this.getOrderList()
    },
    // 每页数量改变触发的事件
    handleSizeChange (newPageSize) {
      this.queryInfo.pagesize = newPageSize
      this.getOrderList()
    },
    // 打开编辑对话框
    showEditDialog () {
      this.editDialogVisible = true
    },
    // 根据单号获取对应的物流信息
    async getOrderInfoprogress () {
      // 测试物流单号
      const { data: res } = await this.$http.get(`/kuaidi/1106975712662`)
      if (res.meta.status !== 200) return this.$message.error('获取物流信息失败')
      this.$message.success('获取物流信息成功')
      this.orderInfoList = res.data
      this.showDialogVisible = true
    }
  }
}
</script>

<style lang="less" scoped>
.el-pagination{
  margin: 15px 0 0 0;
}
.el-cascader{
  width: 100%;
}

</style>
